package com.xxzb.dao;

import com.xxzb.bean.Dept;
import com.xxzb.db.DBManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class DeptDAO {
    private Connection conn;
    private PreparedStatement ps;
    private ResultSet rs;

    public List<Dept> find(){
        String sql="select * from gaofeng2207.dept";
        List<Dept> list=new ArrayList<>();
        try {
            conn= DBManager.getConnection();
            ps=conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()){
                int deptNo=rs.getInt(1);
                String dname=rs.getString(2);
                String loc=rs.getString(3);
                Dept dept=new Dept(deptNo,dname,loc);
                list.add(dept);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

}
